package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.SysCheckItem;
import com.ruoyi.system.service.ISysCheckItemService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 检查项目Controller
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/check/Check_Item")
public class SysCheckItemController extends BaseController
{
    @Autowired
    private ISysCheckItemService sysCheckItemService;

    /**
     * 查询检查项目列表
     */
    @PreAuthorize("@ss.hasPermi('check:Check_Item:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysCheckItem sysCheckItem)
    {
        startPage();
        List<SysCheckItem> list = sysCheckItemService.selectSysCheckItemList(sysCheckItem);
        return getDataTable(list);
    }

    /**
     * 导出检查项目列表
     */
    @PreAuthorize("@ss.hasPermi('check:Check_Item:export')")
    @Log(title = "检查项目", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysCheckItem sysCheckItem)
    {
        List<SysCheckItem> list = sysCheckItemService.selectSysCheckItemList(sysCheckItem);
        ExcelUtil<SysCheckItem> util = new ExcelUtil<SysCheckItem>(SysCheckItem.class);
        util.exportExcel(response, list, "检查项目数据");
    }

    /**
     * 获取检查项目详细信息
     */
    @PreAuthorize("@ss.hasPermi('check:Check_Item:query')")
    @GetMapping(value = "/{itemId}")
    public AjaxResult getInfo(@PathVariable("itemId") Long itemId)
    {
        return success(sysCheckItemService.selectSysCheckItemByItemId(itemId));
    }

    /**
     * 新增检查项目
     */
    @PreAuthorize("@ss.hasPermi('check:Check_Item:add')")
    @Log(title = "检查项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysCheckItem sysCheckItem)
    {
        return toAjax(sysCheckItemService.insertSysCheckItem(sysCheckItem));
    }

    /**
     * 修改检查项目
     */
    @PreAuthorize("@ss.hasPermi('check:Check_Item:edit')")
    @Log(title = "检查项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysCheckItem sysCheckItem)
    {
        return toAjax(sysCheckItemService.updateSysCheckItem(sysCheckItem));
    }

    /**
     * 删除检查项目
     */
    @PreAuthorize("@ss.hasPermi('check:Check_Item:remove')")
    @Log(title = "检查项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{itemIds}")
    public AjaxResult remove(@PathVariable Long[] itemIds)
    {
        return toAjax(sysCheckItemService.deleteSysCheckItemByItemIds(itemIds));
    }

    @GetMapping("/getAll")
    public TableDataInfo getAll() {
        startPage();
        List<SysCheckItem> list = sysCheckItemService.selectSysCheckItemList(null); // 使用null作为查询条件，表示查询所有数据
        return getDataTable(list);
    }
}
